/*
 * PDatosBasicos.java
 *
 * Created on 6 de diciembre de 2007, 12:22 PM
 */
package ig.metrica.ui.matriz.correlacion.calculada;

import ejb.metrica.matriz.correlacion.MatrizDTO;
import ig.metrica.ui.matriz.correlacion.calculada.modelo.IModeloWizzar;
import ig.util.Fechas;
import ig.util.MetaFabricaFormateadores;
import java.util.Hashtable;
import javax.swing.JFormattedTextField;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author  Jimmy
 */
public class PDatosBasicos extends javax.swing.JPanel implements IModeloWizzar {

    MWizzar aThis = null;
    /** Creates new form PDatosBasicos */

    public PDatosBasicos(MWizzar aThis) {
        this.aThis = aThis;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        TNombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TADescripcion = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        Fecha = this.getFormattedTextField();//new javax.swing.JFormattedTextField();

        setName("Datos basicos"); // NOI18N

        jLabel1.setText("Nombre de la Nueva Matriz de Correlación");

        jLabel2.setText("Descripción");

        TADescripcion.setColumns(20);
        TADescripcion.setRows(5);
        jScrollPane1.setViewportView(TADescripcion);

        jLabel3.setText("Fecha de definición");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(58, 58, 58)
                                .addComponent(TNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 406, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(Fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(69, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField Fecha;
    private javax.swing.JTextArea TADescripcion;
    private javax.swing.JTextField TNombre;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    public void siguiente() throws Exception {

    }

    public void finalizar() throws Exception {
        validar();
    }
    private void validar(){
        errores=null;
        if(this.TNombre.getText().trim().equals(""))
            errores="No se escribio un nombre para la nueva matriz de correlaci\u00F3n\nEscriba un nombre para la nueva matriz";
        else if(this.TADescripcion.getText().trim().equals(""))
            errores="No se escribio una descripci\u00F3n\nEscriba un adescripci\u00F3n";
    }
            
    public void calcelar() throws Exception {
        
    }
    
    public void setObject(Object obj) throws Exception {
        errores=null;
        //System.out.println(obj instanceof Object[][]);
        datos.putAll((Hashtable)obj);
    }
    private Hashtable datos=new Hashtable();
    public Object getObject() {
        MatrizDTO dto=new MatrizDTO();
        
        String[] fechas=this.Fecha.getText().split("/");
        
        dto.setDescripcion(this.TADescripcion.getText());
        dto.setFechaPublicacion(java.sql.Timestamp.valueOf(fechas[2]+"-"+fechas[1]+"-"+fechas[0]+" 00:00:00"));
        dto.setNombre(this.TNombre.getText());
        dto.setTipo(0);
        dto.setId(-1);
        dto.setNumfactores(((Object[][])datos.get("MATRIZ")).length);
        
        datos.put("DTO", dto);
        return datos;
    }
    
    public boolean isSiguiente(){
        return true;
    }    
    
    private JFormattedTextField getFormattedTextField() {
        if (Fecha == null) {
            Fecha = new JFormattedTextField();
            DefaultFormatterFactory dff = null;
            try {
                JFormattedTextField.AbstractFormatter displayFormatter = new MaskFormatter("##/##/####");
                dff = new DefaultFormatterFactory(displayFormatter, displayFormatter, displayFormatter);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Fecha.setFormatterFactory(dff);
            Fecha.setInputVerifier(MetaFabricaFormateadores.getDateVerifier());
            Fecha.setText(Fechas.getFormatoStringNOBS());
        }
        return Fecha;
    }
    private String errores=null;
    public String getErrores() {
        return errores;
    }
    
}
